#ifndef _IODRIVE_H_
#define _IODRIVE_H_
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <queue>

#include "reactor.h"
#include "safequeue.h"
#include "user.h"
#include "serialport.h"
#include "RMVideoCapture.h"

using namespace std;
using namespace cv;
#if(CAMER_NUM == 1)
typedef struct
{
    Mat frame;
    bool isusing;
}MatVector;
#elif(CAMER_NUM == 2)
typedef struct
{
    Mat frame_1;
    Mat frame_2;
    bool isusing;
}MatVector;
#endif



extern MatVector frame_v[5];
extern int framev_index;
extern SafeQueue <MatVector *> frame_que;
class IODrive
{
public:
    IODrive();
    ~IODrive(){;}

    /*　更新图像　*/
    void updataVidio(int fd);
    /* 定时获取图像。定时调用opencv采集函数　*/
    void getVidio(int time_ms)
    {
        reactor.addTimer(time_ms,bind(&IODrive::updataVidio, this,std::placeholders::_1));
    }

    /* 打印帧率　*/
    void disp_fps(int fd)
    {
        char a[8];
        read(fd,a,8);
        std::cout << "fps: " << fps << std::endl;
        fps = 0;
    }
    /* 显示图像处理帧率　*/
    void showFps()
    {
        reactor.addTimer(1000,bind(&IODrive::disp_fps, this,std::placeholders::_1));
    }

    void start()
    {
        reactor.loop();
    }
public:
    #ifdef USING_UART2
    SerialPort *Uart2;
    #endif // USE_UART2

    #ifdef USING_UART3
    SerialPort *Uart3;
    #endif // USE_UART2


private:

    RMVideoCapture capture;
    #if(CAMER_NUM == 2)
    RMVideoCapture capture_2;
    #endif
    int fps;
    Reactor reactor;
};
#endif
